/**package com.heraclito.heraclitoapp;

import java.io.IOException;
import java.util.Timer;
import java.util.TimerTask;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import org.xmlpull.v1.XmlPullParserException;

import com.heraclito.heraclitoapp.R;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.graphics.Color;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ProgressBar;
import android.widget.TextSwitcher;
import android.widget.TextView;
import android.widget.Toast;

import webservices.Constants;

public class LoginActivity extends Activity {

	SoapObject request = new SoapObject(Constants.NAMESPACE,
			Constants.METHOD_NAME);
	static SoapObject request3 = new SoapObject(Constants.NAMESPACE, Constants.METHOD_NAME3);

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		final Dialog login_dialog = new Dialog(this);
		login_dialog.setTitle(getResources().getString(R.string.login));
		login_dialog.setContentView(R.layout.login);

		final Button login_ok = (Button) login_dialog
				.findViewById(R.id.login_ok);
		final Button login_cancelar = (Button) login_dialog
				.findViewById(R.id.login_cancelar);

		final EditText login_caixa = (EditText) login_dialog
				.findViewById(R.id.login_caixa);
		final EditText login_password = (EditText) login_dialog
				.findViewById(R.id.login_password);

		final ProgressBar progress = (ProgressBar) login_dialog
				.findViewById(R.id.progressBar1);
		final TextSwitcher mensagemLogin = (TextSwitcher) login_dialog
				.findViewById(R.id.mensagemLogin);

		final TextView mensagemLogadoComo = (TextView) findViewById(R.id.logadoComo);

		login_ok.setOnClickListener(new View.OnClickListener() {

			public void onClick(View v) {
				TabActivity.usuario = login_caixa.getText().toString();
				TabActivity.senha = login_password.getText().toString();

				Animation in = AnimationUtils.loadAnimation(getBaseContext(),
						android.R.anim.fade_in);
				Animation out = AnimationUtils.loadAnimation(getBaseContext(),
						android.R.anim.fade_out);

				mensagemLogin.setInAnimation(in);
				mensagemLogin.setOutAnimation(out);

				if (mensagemLogin.getChildCount() > 0) {
					mensagemLogin.removeAllViews();
				}

				mensagemLogin.addView(new TextView(getBaseContext()));
				mensagemLogin.addView(new TextView(getBaseContext()));

				new Login(getBaseContext(), progress, login_dialog,
						mensagemLogin, mensagemLogadoComo).execute(
						TabActivity.usuario, TabActivity.senha);
			}
		});

		login_cancelar.setOnClickListener(new View.OnClickListener() {

			public void onClick(View v) {

				login_dialog.dismiss();
			}
		});

		login_dialog.show();
	}

	public class Login extends AsyncTask<String, String, String> {
		ProgressBar progressBar;
		Context mContext;
		Dialog loginDialog;
		TextSwitcher mensagemLogin;
		TextView mensagemUsuarioLogado;
		String mensagemUsuarioUser;

		public Login(Context mContext, ProgressBar mProgressBar,
				Dialog loginDialog, TextSwitcher mensagemLogin,
				TextView mensagemUsuarioLogado) {
			this.mContext = mContext;
			this.progressBar = mProgressBar;
			this.loginDialog = loginDialog;
			this.mensagemLogin = mensagemLogin;
			this.mensagemUsuarioLogado = mensagemUsuarioLogado;
		}

		@Override
		protected void onPreExecute() {

			AlphaAnimation fadeIn;
			fadeIn = new AlphaAnimation(0, 1); // fade out animation from 1
												// (fully visible) to 0
												// (transparent)
			fadeIn.setDuration(150); // set duration in mill seconds
			// fadeIn.setFillAfter(true);
			progressBar.startAnimation(fadeIn);

			TextView loginTexto = (TextView) mensagemLogin.getChildAt(0);
			loginTexto.setTextColor(Color.BLACK);

			TextView loginTexto2 = (TextView) mensagemLogin.getChildAt(1);
			loginTexto2.setTextColor(Color.BLACK);

			progressBar.setVisibility(View.VISIBLE);
			mensagemLogin.setText(getResources().getString(
					R.string.autenticando)
					+ "...");
		}

		@Override
		protected String doInBackground(String... params) {
			mensagemUsuarioUser = params[0];

			request.addProperty("userId", params[0]);
			request.addProperty("password", params[1]);
			request.addProperty("localHost", "");

			SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
					SoapEnvelope.VER11);
			envelope.setOutputSoapObject(request);

			HttpTransportSE transport = new HttpTransportSE(Constants.URL);
			String resposta = new String();

			try {
				transport.call(Constants.SOAP_ACTION, envelope);

				Object response = envelope.getResponse();

				if (response != null) {
					if (response instanceof SoapPrimitive) {
						SoapPrimitive respostaAgente = (SoapPrimitive) response;
						resposta = respostaAgente.toString();
					} else if (response instanceof SoapObject) {
						// SoapObject answerAgent = (SoapObject) response;

						resposta = getResources().getString(
								R.string.login_invalido);
						/**
						 * for (int i = 0; i < answerAgent.getPropertyCount();
						 * i++) { resposta +=
						 * answerAgent.getProperty(i).toString(); }
						 **/
/**

					}
					// mensagemLogin.setCurrentText(resposta);
					// Toast.makeText(getBaseContext(), response.toString(),
					// Toast.LENGTH_LONG).show();
				}

			} catch (IOException e) {

				e.printStackTrace();
			} catch (XmlPullParserException e) {

				e.printStackTrace();
			}

			publishProgress();
			// Toast.makeText(mContext, resposta, Toast.LENGTH_LONG).show();
			return resposta;
		}

		@Override
		protected void onPostExecute(String result) {
			// espera();

			// progressBar.setVisibility(View.GONE);
			if (result != null) {

				// Toast.makeText(mContext, result, Toast.LENGTH_LONG).show();
				if (!result.contains("logado")) {
					mensagemLogin.setText(result);
				}

				AlphaAnimation fadeOut;
				fadeOut = new AlphaAnimation(1, 0); // fade out animation from 1
													// (fully visible) to 0
													// (transparent)
				fadeOut.setDuration(3100); // set duration in mill seconds
				fadeOut.setFillAfter(true);
				progressBar.startAnimation(fadeOut);

				if (result.contains("Erro") || result.contains("Digite")) {
					return;
				} else {
					espera();

					// loginDialog.dismiss();
				}

			} else {
				mensagemLogin.setText(getResources().getString(
						R.string.impossivel_login));
				// Toast.makeText(mContext, "não foi possível fazer login",
				// Toast.LENGTH_LONG).show();
			}

			// Toast.makeText(mContext, result, Toast.LENGTH_SHORT).show();
		}

		@Override
		protected void onProgressUpdate(String... values) {

			// progressBar.setProgress(0x1);
			// Toast.makeText(mContext, values[0], Toast.LENGTH_SHORT).show();
		}

		public void espera() {
			final Handler handler = new Handler();

			Timer t = new Timer();
			t.schedule(new TimerTask() {
				public void run() {
					handler.post(new Runnable() {
						public void run() {
							loginDialog.dismiss();
							mensagemUsuarioLogado.setText(mensagemUsuarioUser);
							
						}
					});
				}
			}, 2500);

		}

	}

}**/
